package spider.impl.chapter;

import spider.entitys.Chapter;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * created by yb
 * on 2017/8/10.
 **/
public class BxwxChapterSpider extends AbstractChapterSpider {
    @Override
    public List<Chapter > getChapter( String url) {
        List<Chapter > chapters = super.getChapter(url);
        Collections.sort(chapters, new Comparator<Chapter >() {
            @Override
            public int compare( Chapter o1, Chapter o2) {
                String o1url = o1.getUrl();
                String o1ur2 = o2.getUrl();
                String o1index = o1url.substring(o1url.lastIndexOf("/") + 1, o1url.lastIndexOf("."));
                String o2index = o1ur2.substring(o1ur2.lastIndexOf("/") + 1, o1ur2.lastIndexOf("."));
                return (int)Integer.parseInt(o1index) - (int)Integer.parseInt(o2index);
            }
        });
        return chapters;
    }
}
